package com.mxpio.erp.technology.service.impl;

import com.mxpio.erp.common.enums.CommonEnums;
import com.mxpio.erp.common.technology.entity.ProcessGroup;
import com.mxpio.erp.common.technology.entity.ProcessGroupLine;
import com.mxpio.erp.common.technology.entity.ProdTecRoutProc;
import com.mxpio.erp.common.technology.service.ProcessGroupService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProcessGroupServiceImpl extends BaseServiceImpl<ProcessGroup> implements ProcessGroupService {

    @Override
    @Transactional(readOnly = true)
    public Page<ProcessGroup> getUnrelatedProcGroupPage(String productItemCode, Pageable pageAble, Criteria criteria) {
        return JpaUtil
                .linq(ProcessGroup.class)
                .collect("procGroupCode", ProcessGroupLine.class,"procGroupCode")
                    .notExists(ProdTecRoutProc.class)
                    .equalProperty("procGroupCode", "procGroupCode")
                    .equal("routId", productItemCode)
                .end()
                .equal("status", CommonEnums.YesNo.YES.getCode())
                .where(criteria)
                .paging(pageAble);
    }
}
